<?php 
header("Pragma: public");
header("Expires: 0");
header("Accept-Ranges: bytes");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type:text/xml");
header('Content-Disposition: attachment; filename=showprofessionscores.doc');
header("Content-Transfer-Encoding: binary");

?>
<h2>Средний балл по специальностям</h2>
<table>
<?php
foreach ($total as $element):
if ($element['Totalscore'] ){
echo '<tr>';
echo '<td>';
echo $professions[$element['profession_id']].' '.$learningforms[$element['learningform_id']].' '.$learningtypes[$element['learningtype_id']];
echo '</td>';
echo '<td>';
if ($element['ids']){
	echo round($element['Totalscore']/count($element['ids']), 2);
}

echo '</td>';
echo '</tr>';}
endforeach;
?>

</table>
<?php 
/* SELECT *
FROM professions ps
LEFT JOIN (
		SELECT sp.profession_id
		, sp.learningform_id
		, sp.learningtype_id
		, SUM(rs.score) / COUNT(sp.abiturient_id)
		FROM selectedprofessions sp
		, professions_subjects psj
		, results rs
		WHERE psj.profession_id = sp.profession_id
		AND  rs.abiturient_id = sp.abiturient_id
		AND  rs.subject_id = psj.subject_id
		GROUP BY sp.profession_id
		, sp.learningform_id
		, sp.learningtype_id
) AS sp
ON ps.id = sp.profession_id; */

?>